package com.cskaoyan.catmall.controller.wx;

import com.cskaoyan.catmall.bean.BaseParam;
import com.cskaoyan.catmall.model.pojo.MarketUser;
import com.cskaoyan.catmall.model.vo.BaseRespVo;
import com.cskaoyan.catmall.model.vo.WxFootListVo;
import com.cskaoyan.catmall.service.WxFootPrintService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * 创建日期: 2022-01-10-13-23
 * author : WQW
 * description: 足迹相关的查找和删除
 */

@RestController
@RequestMapping("wx/footprint")
public class WxFootPrintController {


    @Autowired
    WxFootPrintService footPrintService;



    /**
     * @description 获取用户所有足迹，并根据前端传入的基本参数进行分页
     * @author WQW
     * @date 2022/1/10 14:08
     * @param
     * @param baseParam 接收前端传入的参数信息
     * @return com.cskaoyan.catmall.model.vo.BaseRespVo
     */
    @GetMapping("list")
    public BaseRespVo list(@Validated BaseParam baseParam){
        MarketUser user = (MarketUser) SecurityUtils.getSubject().getPrincipal();
        if (user == null){
            return BaseRespVo.fail("请先登录");
        }
        WxFootListVo wxFootListVo = footPrintService.getAllFootPrint(baseParam,user.getId());
        return BaseRespVo.ok(wxFootListVo);
    }

    /**
     * @description 删除指定历史足迹
     * @author WQW
     * @date 2022/1/11 14:07
     * @param
     * @param map
     * @return com.cskaoyan.catmall.model.vo.BaseRespVo
     */
    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody Map<String,Integer> map){
        int result = footPrintService.deleteFootPrint(map.get("id"));
        if (result == 200){
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("删除足迹失败");
    }
}
